package leetcode.greed;

// [7,1,5,3,6,4]
public class Test122 {

    public static void main(String[] args) {
        int[] a = {7,6,4,3,1};
        int i = maxProfit(a);
        System.out.println(i);
    }

    public static int maxProfit(int[] prices) {
        int index = 1;
        int total = 0;
        if (prices.length < 2){
            return 0;
        }
        while (index<prices.length){
            if (prices[index]>prices[index-1]){
                total = total+(prices[index]-prices[index-1]);
            }
            index++;
        }
        return total;
    }
}
